/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import entities.User;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author Thanh
 */
public class DeleteUserDAO {
    public int deleteUser(String id) {
        int result = 0;
        try {
            String un = "sa";
            String pw = "1234";
            String url = "jdbc:sqlserver://localhost:1433;databaseName=BloggerDB;";
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection con = java.sql.DriverManager.getConnection(url, un, pw);

            String sql = "delete Users where UserID = ? and RoleID <> 1";
            PreparedStatement stm = con.prepareStatement(sql);
            stm.setString(1, id);
            result = stm.executeUpdate();
            stm.close();
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
